<template>
  <div class="container">

    <!-- hotcity -->
    <div>
      <div class="hotcity-title">热门城市</div>
      <ul class="hotcity-list">
        <li class="hotcity-item" @click="changecity(item.name)" v-for="item in hotCities" :key="item.id">
          {{item.name}}
        </li>
      </ul>
    </div>

    <!-- sort -->
    <div>
      <div class="sort-title">字母排序</div>
      <ul class="sort-list">
        <li class="sort-item"  v-for="(val,key) in cities">
          {{key}}
        </li>
      </ul>
    </div>

    <!-- list -->
    <div class="list">
      <div v-for="(val,key) in cities" >
        <div class="list-title">
          {{ key }}
        </div>
        <ul class="list-msg">
          <li class="list-item" @click="changecity(item.name)" v-for="item in val" :key="item.id" >
            {{ item.name }}
          </li>
        </ul>
      </div>
    </div>

  </div>
</template>

<script>
import BScorll from 'better-scroll';
import {mapMutations} from "vuex";

export default {
  name: "list",
  props: ["hotCities","cities"],
  methods:{
    // changeSort(sortName){
    //   // this.scroll.scrollToElement(this.$refs[sortName][0])
    //   console.log(this.$refs[sortName][0]);
    // }
    changecity(cityName){
      this.changeCity(cityName)

      this.$router.push('/')
      // console.log(cityName);
    },
    ...mapMutations(['changeCity'])
  }
}
</script>

<style scoped>
  .container{
    position: absolute;
    overflow-x: hidden;
    left: 0;
    right: 0;
    bottom: 0;
    top: .88rem;
    background: #f5f5f5;
  }
  /*hotcity*/
  .hotcity-title{
    font-size: .24rem;
    color: #212121;
    padding: .2rem .3rem;
  }
  .hotcity-list{
    background: #fff;
    color: #212121;
    font-size: .28rem;
    overflow: hidden;
    position: relative;
  }
  .hotcity-list:before{
    content: " ";
    position: absolute;
    height: 100%;
    width: 33.33333%;
    left: 33.33333%;
    border-right: .02rem solid #ddd;
    border-left: .02rem solid #ddd;
  }
  .hotcity-item{
    position: relative;
    text-align: center;
    width: 33.33333%;
    height: .9rem;
    line-height: .9rem;
    float: left;
    border-bottom: .02rem solid #ddd;
  }

  /*sort*/
  .sort-title{
    font-size: .24rem;
    color: #212121;
    padding: .2rem .3rem;
  }
  .sort-list{
    background: #fff;
    color: #212121;
    font-size: .28rem;
    overflow: hidden;
    position: relative;
  }
  .sort-item{
    text-align: center;
    width: 16.6666%;
    height: .9rem;
    line-height: .9rem;
    float: left;
  }

  /*list*/
  .list-title{
    font-size: .24rem;
    color: #212121;
    padding: .2rem .3rem;
    background: #f5f5f5;
  }
  .list-msg{
    position: relative;
    background: #fff;
    overflow: hidden;
  }
  .list-msg:before {
    content: " ";
    position: absolute;
    left: 25%;
    width: 25%;
    height: 100%;
    border-left: .02rem solid #ddd;
    border-right: .02rem solid #ddd;
  }
  .list-msg:after {
    content: " ";
    position: absolute;
    left: 75%;
    width: 0%;
    height: 100%;
    border-left: .02rem solid #ddd;
  }
  .list-item{
    position: relative;
    width: 25%;
    font-size: .28rem;
    text-align: center;
    line-height: .9rem;
    float: left;
    border-bottom: .02rem solid #ddd;
    /*超出范围变成 ...*/
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }

</style>
